package com.sailfish.springbootdemo.dao.db1;

import com.sailfish.springbootdemo.common.DB1TableName;
import com.sailfish.springbootdemo.pojo.db1.PcbaDevice;
import com.sailfish.springbootdemo.pojo.db1.PcbaDeviceAudit;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.Date;
import java.util.List;

public interface PcbaDeviceAuditDao {

    /**
     * 查询所有
     *
     * @return
     */
    @Results(id = "pcbaDeviceAuditResultMap", value = {
            @Result(column = "pcba_device_id", property = "pcbaDeviceId", jdbcType = JdbcType.INTEGER),
            @Result(column = "pcba_device_name_cn", property = "pcbaDeviceNameCn", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pcba_device_name_en", property = "pcbaDeviceNameEn", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "pcba_device_type_id", property = "pcbaDeviceTypeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "pcba_line_id", property = "pcbaLineId", jdbcType = JdbcType.INTEGER),
            @Result(column = "pcba_device_resource_id", property = "pcbaDeviceResourceId", jdbcType = JdbcType.INTEGER),
            @Result(column = "asset_number", property = "assetNumber", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_time", property = "productTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "purpose", property = "purpose", jdbcType = JdbcType.VARCHAR),
            @Result(column = "begin_time", property = "beginTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "end_time", property = "endTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "is_filled_tech_params_actual", property = "isFilledTechParamsActual", jdbcType = JdbcType.INTEGER),
            @Result(column = "params_status", property = "paramsStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "is_filled_upkeep", property = "isFilledUpkeep", jdbcType = JdbcType.INTEGER),
            @Result(column = "upkeep_status", property = "upkeepStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "params_notes", property = "paramsNotes", jdbcType = JdbcType.VARCHAR),
            @Result(column = "submitter", property = "submitter", jdbcType = JdbcType.INTEGER),
            @Result(column = "auditors", property = "auditors", jdbcType = JdbcType.VARCHAR),
            @Result(column = "loop_close_status", property = "loopCloseStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "loop_close_time", property = "loopCloseTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "loop_close_user", property = "loopCloseUser", jdbcType = JdbcType.INTEGER),
            @Result(column = "loop_close_last_send_time", property = "loopCloseLastSendTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "age_close_status", property = "ageCloseStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "age_close_time", property = "ageCloseTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "age_close_user", property = "ageCloseUser", jdbcType = JdbcType.INTEGER),
            @Result(column = "age_close_last_send_time", property = "ageCloseLastSendTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "age_close_flag", property = "ageCloseFlag", jdbcType = JdbcType.INTEGER),
    })
    @Select("select * from " + DB1TableName.PCBA_DEVICE_AUDIT + " where pcba_line_id = #{pcbaLineId}")
    List<PcbaDeviceAudit> getAllPcbaDeviceAuditByLine(@Param("pcbaLineId") Integer pcbaLineId);

    /**
     * 根据id查询
     *
     * @param pcbaDeviceId
     * @return
     */
    @ResultMap(value = "pcbaDeviceAuditResultMap")
    @Select("select * from " + DB1TableName.PCBA_DEVICE_AUDIT + " where pcba_device_id = #{pcbaDeviceId}")
    PcbaDeviceAudit getById(@Param("pcbaDeviceId") Integer pcbaDeviceId);

    /**
     * 删除
     *
     * @param pcbaDeviceId
     * @return
     */
    @Delete("delete from " + DB1TableName.PCBA_DEVICE_AUDIT + " where pcba_device_id = #{pcbaDeviceId}")
    Integer deleteById(@Param("pcbaDeviceId") Integer pcbaDeviceId);

    /**
     * 新增
     *
     * @param pcbaDevice
     * @return
     */
    @Insert("insert into " + DB1TableName.PCBA_DEVICE_AUDIT + "(" +
            "pcba_device_id," +
            "pcba_device_name_cn," +
            "pcba_device_name_en," +
            "create_time," +
            "update_time," +
            "status," +
            "pcba_device_type_id," +
            "sort," +
            "pcba_line_id," +
            "pcba_device_resource_id," +
            "asset_number," +
            "product_time," +
            "purpose," +
            "begin_time," +
            "end_time," +
            "is_filled_tech_params_actual," +
            "params_status," +
            "is_filled_upkeep," +
            "upkeep_status," +
            "params_notes," +
            "submitter," +
            "auditors," +
            "loop_close_status," +
            "loop_close_time," +
            "loop_close_user," +
            "loop_close_last_send_time," +
            "age_close_status," +
            "age_close_time," +
            "age_close_user," +
            "age_close_last_send_time," +
            "age_close_flag) values " +
            "(#{pcbaDevice.pcbaDeviceId}," +
            "#{pcbaDevice.pcbaDeviceNameCn}," +
            "#{pcbaDevice.pcbaDeviceNameEn}," +
            "#{pcbaDevice.createTime}," +
            "#{pcbaDevice.updateTime}," +
            "#{pcbaDevice.status}," +
            "#{pcbaDevice.pcbaDeviceTypeId}," +
            "#{pcbaDevice.sort}," +
            "#{pcbaDevice.pcbaLineId}," +
            "#{pcbaDevice.pcbaDeviceResourceId}," +
            "#{pcbaDevice.assetNumber}," +
            "#{pcbaDevice.productTime}," +
            "#{pcbaDevice.purpose}," +
            "#{pcbaDevice.beginTime}," +
            "#{pcbaDevice.endTime}," +
            "#{pcbaDevice.isFilledTechParamsActual}," +
            "#{pcbaDevice.paramsStatus}," +
            "#{pcbaDevice.isFilledUpkeep}," +
            "#{pcbaDevice.upkeepStatus}," +
            "#{pcbaDevice.paramsNotes}," +
            "#{pcbaDevice.submitter}," +
            "#{pcbaDevice.auditors}," +
            "#{pcbaDevice.loopCloseStatus}," +
            "#{pcbaDevice.loopCloseTime}," +
            "#{pcbaDevice.loopCloseUser}," +
            "#{pcbaDevice.loopCloseLastSendTime}," +
            "#{pcbaDevice.ageCloseStatus}," +
            "#{pcbaDevice.ageCloseTime}," +
            "#{pcbaDevice.ageCloseUser}," +
            "#{pcbaDevice.ageCloseLastSendTime}," +
            "#{pcbaDevice.ageCloseFlag}" +
            ")")
    Integer addPcbaDeviceAudit(@Param("pcbaDevice") PcbaDeviceAudit pcbaDevice);

    /**
     * 删除
     *
     * @param pcbaLineId
     * @return
     */
    @Delete("delete from " + DB1TableName.PCBA_DEVICE_AUDIT + " where pcba_line_id = #{pcbaLineId}")
    Integer deleteByLineId(@Param("pcbaLineId") Integer pcbaLineId);

    /**
     * 更新
     *
     * @param pcbaDevice
     * @return
     */
    @Update("<script>" +
            "update " + DB1TableName.PCBA_DEVICE_AUDIT +
            "<set>" +
            "<if test='pcbaDevice.pcbaDeviceNameCn != null and pcbaDevice.pcbaDeviceNameCn != \"\" '>" +
            " pcba_device_name_cn = #{pcbaDevice.pcbaDeviceNameCn}," +
            "</if>" +
            "<if test='pcbaDevice.pcbaDeviceNameEn != null and pcbaDevice.pcbaDeviceNameEn != \"\" '>" +
            " pcba_device_name_en = #{pcbaDevice.pcbaDeviceNameEn}," +
            "</if>" +
            "<if test='pcbaDevice.updateTime != null '>" +
            " update_time = #{pcbaDevice.updateTime}," +
            "</if>" +
            "<if test='pcbaDevice.status != null and pcbaDevice.status != \"\" '>" +
            " status = #{pcbaDevice.status}," +
            "</if>" +
            "<if test='pcbaDevice.pcbaDeviceTypeId != null and pcbaDevice.pcbaDeviceTypeId != \"\" '>" +
            " pcba_device_type_id = #{pcbaDevice.pcbaDeviceTypeId}," +
            "</if>" +
            "<if test='pcbaDevice.sort != null and pcbaDevice.sort != \"\" '>" +
            " sort = #{pcbaDevice.sort}," +
            "</if>" +
            "<if test='pcbaDevice.pcbaLineId != null and pcbaDevice.pcbaLineId != \"\" '>" +
            " pcba_line_id = #{pcbaDevice.pcbaLineId}," +
            "</if>" +
            "<if test='pcbaDevice.pcbaDeviceResourceId != null and pcbaDevice.pcbaDeviceResourceId != \"\" '>" +
            " pcba_device_resource_id = #{pcbaDevice.pcbaDeviceResourceId}," +
            "</if>" +
            "<if test='pcbaDevice.assetNumber != null and pcbaDevice.assetNumber != \"\" '>" +
            " asset_number = #{pcbaDevice.assetNumber}," +
            "</if>" +
            "<if test='pcbaDevice.productTime != null'>" +
            " product_time = #{pcbaDevice.productTime}," +
            "</if>" +
            "<if test='pcbaDevice.purpose != null '>" +
            " purpose = #{pcbaDevice.purpose}," +
            "</if>" +
            "</set>" +
            " where pcba_device_id = #{pcbaDevice.pcbaDeviceId}" +
            "</script>")
    Integer updatePcbaDeviceAudit(@Param("pcbaDevice") PcbaDeviceAudit pcbaDevice);
}
